﻿using System;
using System.Collections.Generic;
using System.Linq;
//using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using BL;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;

namespace WebsiteBanHang
{
    public partial class TrangDangNhapUser : System.Web.UI.Page
    {
        NguoiDung_DAL nd = new NguoiDung_DAL();
        NguoiDungBL nguoiDung = new NguoiDungBL();

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void LayNguoiDungTheoTaiKhoan(string taikhoan)
        {
            nd = nguoiDung.LayNguoiDungTheoTaiKhoan(taikhoan);

            txtTaiKhoan.Text = taikhoan;
            txtMatKhau.Text = nd.Matkhau;
            txtHoTen.Text = nd.Hoten;
            txtDiaChi.Text = nd.Diachi;
            txtEmail.Text = nd.Email;
            txtSoDienThoai.Text = nd.Sodienthoai;
            txtGhiChu.Text = nd.Ghichu;
        }

        protected void btn_CapNhat_Click(object sender, EventArgs e)
        {
            string taikhoan = Session["TaiKhoan"].ToString();
            bool ok = nguoiDung.SuaNguoiDungTheoTaiKhoan(txtMatKhau.Text,
                                                         "Thành Viên",
                                                         txtHoTen.Text,
                                                         txtDiaChi.Text,
                                                         txtEmail.Text,
                                                         txtSoDienThoai.Text,
                                                         txtGhiChu.Text,
                                                         taikhoan);
            if (ok == true)
            {
                lb_Thongbao.Text = "Sửa Thành Công!!";
                lb_Thongbao.Visible = true;
                LayNguoiDungTheoTaiKhoan(taikhoan);
            }
            else
            {
                lb_Thongbao.Text = "Sửa Thất bại!!";
                lb_Thongbao.Visible = true;
            }
        }

        protected void lbt_TroVeTrangChu_Click(object sender, EventArgs e)
        {
            Response.Redirect("Default.aspx");
        }

        protected void lbt_Sua_Click(object sender, EventArgs e)
        {
            btn_CapNhat.Visible = true;

            txtMatKhau.ReadOnly = false;
            txtHoTen.ReadOnly = false;
            txtEmail.ReadOnly = false;
            txtDiaChi.ReadOnly = false;
            txtSoDienThoai.ReadOnly = false; 
        }

        protected void bnt_XemThongTin_Click(object sender, EventArgs e)
        {
            btn_XemThongTin.Visible = false;

            lbt_Sua.Visible = true;
            lbt_TroVeTrangChu.Visible = true;

            lb_TaiKhoan.Visible = true;
            lb_MatKhau.Visible = true;
            lb_HoTen.Visible = true;
            lb_DiaChi.Visible = true;
            lb_Email.Visible = true;
            lb_SoDienThoai.Visible = true;        

            txtTaiKhoan.Visible = true;
            txtMatKhau.Visible = true;
            txtHoTen.Visible = true;
            txtDiaChi.Visible = true;
            txtEmail.Visible = true;
            txtSoDienThoai.Visible = true; 

            string taikhoan = Session["TaiKhoan"].ToString();
            LayNguoiDungTheoTaiKhoan(taikhoan);
        }
      
    }
}